package com.beyond.pm.component

import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.lazy.grid.GridCells
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.itemsIndexed
import androidx.compose.foundation.lazy.grid.rememberLazyGridState
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.beyond.pm.adapter.LazyGridAdapter
import com.beyond.pm.ext.simpleVerticalScrollbar

@Composable
fun MyLazyVerticalGrid(
    modifier: Modifier = Modifier,
    contentPadding: PaddingValues = PaddingValues(),
    dataList: List<Any>,
    adapter: LazyGridAdapter,
) {
    val listState = rememberLazyGridState()
    LazyVerticalGrid(
        modifier = modifier.simpleVerticalScrollbar(listState),
        columns = GridCells.Adaptive(100.dp),
        state = listState,
        contentPadding = PaddingValues(
            start = 16.dp,
            top = contentPadding.calculateTopPadding(),
            end = 16.dp,
            bottom = contentPadding.calculateBottomPadding()
        ),
        verticalArrangement = Arrangement.spacedBy(0.dp),
        horizontalArrangement = Arrangement.spacedBy(0.dp)
    ) {
        itemsIndexed(
            items = dataList,
        ) { index, item ->
            adapter.Draw(
                modifier = Modifier,
                index = index,
                data = item
            )
        }
    }
}